package com.acme.bankapp.domain.bank;

import java.io.Serializable;

public abstract class AbstractAccount implements Account, Serializable {

	protected int id;
	protected double balance;

	public AbstractAccount(final double amount, int id) {
		balance = amount;
		this.id = id;
	}
	
	public AbstractAccount(int id) {		
		this(0, id);
	}
	
	public AbstractAccount() {
		this(0, 0);
	}	
	
	public AbstractAccount(double amount) {
		this(amount, 0);
	}

	public int decimalValue() {
		int dVal = Math.round((float)balance);
		if (dVal > balance) {
			return dVal - 1;
		} else {
			return dVal;
		}
	}

	public int hashCode() {
		return id;
	}

	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof AbstractAccount)) {
			return false;
		}
		AbstractAccount other = (AbstractAccount) obj;
		if (id != other.id) {
			return false;
		}
		return true;
	}

	public double getBalance() {
		return balance;
	}
	
	public int getID() {
		return id;
	}

	public void deposit(final double amount) throws IllegalArgumentException {
		if(amount <= 0) {
			throw new IllegalArgumentException("the wrong amount");
		} 
		this.balance += amount;
	}	
}
